package com.weishu.housing.utils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
import org.springframework.data.elasticsearch.core.query.IndexQuery;
import org.springframework.data.elasticsearch.core.query.IndexQueryBuilder;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @ClassName: ESUtils
 * @Description: TODO
 * @author:
 * @date: 2019年7月24日 上午10:14:13
 *  System.setProperty("es.set.netty.runtime.available.processors","false");
 */
@Component
public class EsHlUtils {

    @Resource
	ElasticsearchRestTemplate elasticsearchTemplate;


	/**
	 * 保存或更新
	 * <p>Title: saveOrUpdate</p>  
	 * <p>Description: </p>  
	 * @param id
	 * @param object
	 */
	public void saveOrUpdate(String id,Object object) {
		IndexQuery withObject = new IndexQueryBuilder().withId(id).withObject(object).build();
		elasticsearchTemplate.save(withObject);
	}
	
	
	/**
	 * 删除
	 * <p>Title: deleteById</p>  
	 * <p>Description: </p>  
	 * @param id
	 * @param clazz
	 */
	public void deleteById(String id,Class clazz) {
		elasticsearchTemplate.delete(id,clazz);
	}

}
